package com.rsk.dao.info.extend;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;


@Component
public class RskInformationExtend {
	
	public Map<String, Object> selectInfoTabByPage(Long labelID, String informationTitle){
		 // 拼接SQL语句
       StringBuilder sql = new StringBuilder("SELECT ri.id,rit.label_name,information_type,information_title");
       		sql.append(",information_photo,information_user,information,information_url,information_source");
    		sql.append(",information_status,information_read FROM rsk_information ri");
    		sql.append(" LEFT JOIN rsk_info_tab rit on ri.label_id = rit.id WHERE ri.is_del = 0");
       StringBuilder countSql = new StringBuilder("SELECT count(ri.id) FROM rsk_information ri");
       		countSql.append(" LEFT JOIN rsk_info_tab rit on ri.label_id = rit.id where ri.is_del = 0 ");
       // 查询需要的参数，先存进Map
       StringBuilder paramSql = new StringBuilder();
       Map<String, Object> paramMap = new HashMap<String, Object>();
       if (labelID != null && labelID>0) {
    	   paramSql.append(" and ri.label_id = :labelID");
    	   paramMap.put("labelID", labelID);
       }
       if (informationTitle != null && !informationTitle.equals("")) {
    	   paramSql.append(" and ri.information_title like :informationTitle");
    	   paramMap.put("informationTitle", "%"+informationTitle+"%");
       }
       
       //排序
       StringBuilder orderSql = new StringBuilder();
       orderSql = orderSql.append(" order by ri.operator_time desc");
       
       Map<String, Object> returnMap = new HashMap<String, Object>();
       returnMap.put("sql", sql.append(paramSql).append(orderSql));
       returnMap.put("countSQL", countSql.append(paramSql));
       returnMap.put("paramMap", paramMap);
		return returnMap;
	}
}
 